<?php
declare (strict_types = 1);

namespace app\controller\backend\system;

use think\App;
use think\response\Json;
use think\db\exception\DbException;
use app\controller\backend\BackendController;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use app\service\logic\backend\system\PermissionsService;

class PermissionsController extends BackendController
{
    protected $service;

    public function __construct(App $app, PermissionsService $service)
    {
        parent::__construct($app);

        $this->service = $service;
    }

    /**
     * @return string
     */
    public function forbidden()
    {
        return $this->layoutWithoutMenu('backend/system/403');
    }

    /**
     * 下拉菜单
     *
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function options()
    {
        $drop = $this->service->getOptions([]);
        return amis(['options' => $drop]);
    }

    /**
     * 按钮权限
     *
     * @return Json
     */
    public function init()
    {
        $frontEnd = invoke(PermissionsService::class)->getFrontEndByAuth();
        $result = [
            'front_end' => $frontEnd,
        ];
        return amis($result);
    }
}
